//
//  Controller-nav.swift
//  Pods
//
//  Created by zhu xietong on 2017/8/8.
//
//

import Foundation
extension UIViewController
{
    
    public func popController(_ step:Int,animated:Bool=true) {
        if let controllers = self.navigationController?.viewControllers
        {
//            print("---KKKSKKS0-----kskaks",controllers)

            if let index = controllers.firstIndex(of: self)
            {
                let pop_index = index - step
                
                if pop_index >= 0
                {
                    let ctr = controllers[pop_index]
//                    print("---KKKSKKS0-----",ctr)
                    _ = self.navigationController?.popToViewController(ctr, animated: animated)
                }
            }
        }
    }
    
    public func popToStep(_ step:Int,animated:Bool=true) {
        if let controllers = self.navigationController?.viewControllers
        {
            let pop_index =  step
            if pop_index >= 0
            {
                let ctr = controllers[pop_index]
                _ = self.navigationController?.popToViewController(ctr, animated: animated)
            }
        }
    }
}
